package com.qf.spring;


import com.qf.spring.framework.MyClassPathXmlApplicationContext;
import com.qf.spring.service.UserService;
import com.qf.spring.service.impl.UserServiceImpl;
import org.junit.Test;

import java.lang.reflect.InvocationTargetException;

/**
 * @Description :模拟IOC容器，理解什么是容器，什么是控制反转，什么是Di依赖注入
 *
 * Spring容器
 * 1.管理bean  bean的创建和维护 IOC
 *
 * 2.bean是属性注入 DI
 *
 */

public class TestIocFactory  {

    //使用IOC容器之前
    @Test
    public void test1() {
        UserService userService = new UserServiceImpl();

        userService.save();
    }
    @Test
    public void test2() throws ClassNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException {
        MyClassPathXmlApplicationContext myClassPathXmlApplicationContext = new MyClassPathXmlApplicationContext("/applicationContext.xml");

       // 从容器中对象中获取bean
       UserService userService = (UserService) myClassPathXmlApplicationContext.getBean("userService");

       userService.save();

    }

}
